import { Router } from 'vue-router'
import { FormInstance } from 'element-plus'
import { LoginParm } from '@/api/user/userModel'
import { userStore } from '@/store/user'
// 登录验证并调用接口
export const useLogin = (router: Router, formEl: FormInstance | undefined, loginModel: LoginParm) => {
  const store = userStore()
  if (!formEl) return
  formEl.validate(async (valid: boolean) => {
    if (valid) {
      store.login(loginModel).then((res) => {
        if (res.data.code == 200) {
          //跳转到首页
          router.push({ path: '/' })
          //   store.getInfo()
        } else {
          ElMessage.error(res.data.msg)
        }
      })
    } else {
      console.log('error submit!')
      return false
    }
  })
}
